﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BarcodeDelay.view
{
    public partial class FrmSiteName : Form
    {
        public FrmSiteName()
        {
            InitializeComponent();
        }


        private void btnSetting_Click(object sender, EventArgs e)
        {
            if(tbSiteName.Text.Trim().Length>1)
            {
                writeTbFile(tbSiteName.Text.Trim());

                this.Close();
            }
            else
            {
                MessageBox.Show("网点名称不能为空");
            }
            
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void writeTbFile(string strSiteName)
        {
            try
            {
                string delFile = System.Environment.CurrentDirectory + "\\" + StoParams.Instance.siteTxtPath;
                if (delFile.EndsWith("txt"))
                {
                    File.Delete(delFile);
                    FileStream bFile = new FileStream(delFile, FileMode.Create);
                    StreamWriter swb = null;
                    if (swb == null)
                    {
                        swb = new StreamWriter(bFile);
                    }
                    StoParams.Instance.register_site = strSiteName;
                    swb.WriteLine("regsite " + strSiteName);

                    swb.Close();
                }
                

            }
            catch (Exception ex)
            {

            }
        }

        private void FrmSiteName_Load(object sender, EventArgs e)
        {
            this.tbSiteName.Text = StoParams.Instance.register_site;
        }
    }
}
